<% content_for :content do %>

  <!-- widget grid -->
  <section id="widget-grid" class="">
  

    <div class="row">
      <div class="col-sm-12">
        <div class="well">

          <%= simple_form_for :traffic, url: search_admin_traffics_path, :defaults => { :input_html => { :class => "form-control" } }, method: 'get', html: { class: "form-inline" } do |f| %>
            <label>设备组</label>
            <%= f.input_field :terminal_group_id, selected: params[:traffic][:terminal_group_id], collection: TerminalGroup.all, label: false, prompt: '请选择设备组' %>
            <label>终端</label>
            <%= f.input_field :terminal, selected: params[:traffic][:terminal], collection: Terminal.includes(:terminal_user,:terminal_order,:terminal_group).all, label: false, prompt: '请选择终端' %>
            &nbsp;&nbsp;
            <label>开始-结束时间</label>
            <div class="form-group string">
            <%= f.text_field :start_date, class: 'form-control datepicker', "data-dateformat" => "yy-mm-dd", value: params[:traffic][:start_date], placeholder: "From" %> 
            </div>
            <div class="form-group string">
            <%= f.text_field :end_date, class: 'form-control datepicker', "data-dateformat" => "yy-mm-dd", value: params[:traffic][:end_date], placeholder: "To" %>
            </div>
            <%= f.submit "搜索", :class => "btn btn-default"%>
          <% end %>

        </div> <!-- end well div -->

      </div>
    </div>

    <!-- row -->
    <div class="row">
  
      <!-- NEW WIDGET START -->
      <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
  
        <!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget jarviswidget-color-darken" id="wid-id-1" data-widget-editbutton="false" data-widget-colorbutton="false" data-widget-deletebutton="false">
          <!-- widget options:
          usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">

          data-widget-colorbutton="false"
          data-widget-editbutton="false"
          data-widget-togglebutton="false"
          data-widget-deletebutton="false"
          data-widget-fullscreenbutton="false"
          data-widget-custombutton="false"
          data-widget-collapsed="true"
          data-widget-sortable="false"

          -->
          <header>
            <span class="widget-icon"> <i class="fa fa-table"></i> </span>
            <h2>流量明细</h2>
          </header>

          <!-- widget div-->
          <div>

            <!-- widget edit box -->
            <div class="jarviswidget-editbox">
              <!-- This area used as dropdown edit box -->
            </div>
            <!-- end widget edit box -->

            <!-- widget content -->
            <div class="widget-body no-padding">

              <div class="alert alert-info no-margin">
                <span class="">
                  <i class="fa-fw fa fa-info"></i>共有<%= @terminals.total_count %>条记录
                </span>
                <span class="col-md-offset">
                  <a class="btn btn-default btn-sm" href="<%= search_admin_traffics_path(format: :csv) %>">导出为CSV</a>
                </span>
              </div>

              <table class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <th>设备组</th>
                    <th>终端</th>
                    <th>流量</th>
                    <th>操作</th>
                  </tr>
                </thead>
                <tbody>
                <% @terminals.each do |terminal| %>
                  <tr id='terminal-<%= terminal.id %>'>
                    <td><%= terminal.terminal_group.try(:group_name) %></td>
                    <td>
                      <%= link_to terminal.mac, stat_admin_traffics_path('stat[start_date]' => params[:traffic][:start_date], 'stat[end_date]' => params[:traffic][:end_date], 'stat[terminal]' => terminal.id) %>
                    </td>
                    <td<%= ' class="text-error"'.html_safe if terminal.is_traffic_warning%>>
                      <%= traffics_friendly_format(terminal.total_flow.to_i) %>
                    </td>          
                    <td>
                      <%= link_to '查看', detail_admin_traffics_path(device_id: terminal.id, start_date: params[:traffic][:start_date], end_date: params[:traffic][:end_date]), remote: true %>
                      <%= link_to '下载', detail_admin_traffics_path(device_id: terminal.id, start_date: params[:traffic][:start_date], end_date: params[:traffic][:end_date], format: 'csv') %>
                    </td>
                  </tr>
                <% end %>
                </tbody>
              </table>

              <div class="dt-row dt-bottom-row"><div class="row"><div class="col-sm-6"><div class="dataTables_info" id="datatable_fixed_column_info"></div></div><div class="col-sm-6 text-right"><%= paginate @terminals %></div></div></div>

            </div>
            <!-- end widget content -->

          </div>
          <!-- end widget div -->

        </div>
        <!-- end widget -->
  
      </article>
      <!-- WIDGET END -->

    </div>
  
    <!-- end row -->

    <div class="row-fluid">
      <div class='span3'>
        <div>
          <%= render :partial => 'charts/line_container',:locals => {:chart_attrs => @chart_attrs,:page_id => 'line_'} if @chart_attrs %>
        </div>
        <div>
          <%= render :partial => 'charts/pie_container',:locals => {:chart_attrs => @pie_chart_attrs,:page_id => 'pie_'} if @chart_attrs %>
        </div>
      </div>
    </div>
  </section>
  <!-- end widget grid -->
<% end %>